<?php
/**
 * 喜欢控制器
 * @author jason <yangjs17@yeah.net> 
 * @version TS3.0
 */
class LikeAction extends Action {
	
	/**
	 * 添加喜欢
	 */
	public function add(){
		$data['wid'] = intval($_POST['wid']);
		$data['uid'] = $this->mid;
		$data['ctime'] = time();
		if(M('like')->add($data)){
			D('Works')->setInc('like_total',array('id'=>$data['wid']));
			$this->ajaxReturn('',"操作成功","1");
		}else{
			$this->ajaxReturn('',"操作失败","0");
		}
	}
	
	/**
	 * 删除喜欢
	 */
	public function del(){
		$data['wid'] = intval($_POST['wid']);
		$data['uid'] = $this->mid;
		if(M('like')->delete($data)){
			D('Works')->setDec('like_total',array('id'=>$data['wid']));
			$this->ajaxReturn('',"取消成功","1");
		}else{
			$this->ajaxReturn('',"取消失败","0");
		}
	}
}